package com.atguigu.day05.HomeWork;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/4 20:48
 * @注释
 */
public class HomeWork8 {
    public static void main(String[] args) {
        String words = "pneumonoultramicroscopicsilicovolcanoconiosis";
        char[] word = words.toCharArray();
        //定义一个数组,用来存储所有单词出现的次数,例如:counts[0] 表示a出现的次数
        int[] counts = new int[26];
        for (int i = 0; i < word.length; i++) {
            counts[word[i] - 'a']++;
        }
        //定义一个整形,用来接受出现最多单词的次数
        int max = counts[0];
        for (int i = 0; i < counts.length; i++) {
            if(counts[i] > max){
                max = counts[i];
            }
        }
        //打印counts中不等于0的单词,不等于0也就代表有出现,等于0表示一次也没有出现
        for (int i = 0; i < counts.length; i++) {
            if(counts[i] != 0){
                System.out.println("单词中出现了以下单词: " + (char)(counts[i] + 97) + " 出现了 " + counts[i] + "次");
            }
        }
        //打印出现最多的字母
        System.out.println( (char)(max + 97));
        }
    }

